<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<% String basePath = request.getContextPath(); %>
<head>
<base href="<%=request.getContextPath()%>/" />
<script> 
window.jQuery || document.write('<script src="http://kiwenlau.com/js/jquery.min.js"><\/script>')
</script>
<title>后台管理系统</title>
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript" src="js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<link rel="stylesheet" type="text/css" href="Styles/bootstrap.min.css" />
</head>
<body>
<h2>草稿修改</h2>     
        <form role="form" id="uploadForm" name="from" method="post">
        <div class="form-group">
        <input style="display:none;" class="form-control" id="gongwenid" value="${dogw.gwId}">
        <label for="name">标题：
         <input type="text" class="form-control" id="title" value="${dogw.title}">
         </label>
         </div>
		 <input type="checkbox" name="box" id="box1" value=1 />常规公文
         <input type="checkbox" name="box" id="box1" value=2 />重要公文
         <input type="checkbox" name="box" id="box1" value=3 />特殊公文
         <input type="checkbox" name="box" id="box1" value=4 />紧急公文
		
		<br/>
		<label>公文内容:
		<textarea id="content" class="ckeditor"  name="content" value="${dogw.content}">${dogw.content} </textarea>
		</label><br/>
		 <input type="file" id="file" name="myfile" />
        <input type="button" value="上传"  onclick="doUpload()"/> 
        <progress id="progressBar" value="0" max="100"></progress>
        <span id="percentage"></span>
        <input id="sp_AjaxFile" name="sp_AjaxFile" value="${dogw.gwAddress}"/><br/>
        <div class="center-block" style="width:200px;">
		<input type="button" value="提交" class="btn btn-default" onclick="from1()"/>
		<input type="button" value="保存草稿" class="btn btn-default" onclick="from2()"/>
		<a role="button" class="button red " id="${dogw.gwId}" onclick="deletes(${dogw.gwId})">删除</a>
		</div>
		<%--  <a href="download?filename=${requestScope.user.image.originalFilename}">
       ${requestScope.user.image.originalFilename }
       </a> --%>
	</form>
	

</body>
 <script type="text/javascript">
 function deletes(gwId){
		var bool = window.confirm("确定删除吗"+gwId);
		if (bool){
			var  id = $("#gongwenid").val();
			 $.post("gongwen/delete.do",{id:id},
			function(data,status){
				 if("success"==data){
					 alert("提交成功！")
				  document.form1.action="<%=basePath %>/check/index";
			   document.form1.method="post";
		    document.form1.submit();

					 }else{
						 alert("删除失败");
					 }
			});
		}
		}
 
 function from1(){
	 var str=document.getElementsByName("box");
	 var objarray=str.length;
	 var chestr="";
	 for (i=0;i<objarray;i++)
	 {
	   if(str[i].checked == true)
	   {
	    chestr+=str[i].value;
	   }
	 }
	 if(chestr == "")
	 {
	   alert("请先选择一个公文级别！");
	 }
	 var options=chestr; 
	 var  url= $("#sp_AjaxFile").val();
	 var  id = $("#gongwenid").val();
	 var  title = $("#title").val();
	 var  content =CKEDITOR.instances.content.getData();
	 $.post("<%=basePath %>/gongwen/bc",{url:url,title:title,content:content,options:options,id:id},
	 function(data,status){
	 if("success"==data){
		 alert("提交成功！")
		    document.form1.action="<%=basePath %>/check/index";
	        document.form1.method="post";
	        document.form1.submit();

	 }else{
	 alert("保存失败！");
	 }
	 });
	}

 function from2(){
	 var str=document.getElementsByName("box");
	 var objarray=str.length;
	 var chestr="";
	 for (i=0;i<objarray;i++)
	 {
	   if(str[i].checked == true)
	   {
	    chestr+=str[i].value;
	   }
	 }
	 if(chestr == "")
	 {
	   alert("请先选择一个公文级别！");
	 }
	 var  url= $("#sp_AjaxFile").val();
	 var  id = $("#gongwenid").val();
	 var  title = $("#title").val();
	 var  content = $("#content").val();
	 $.post("<%=basePath %>/gongwen/cg",{url:url,title:title,content:content,options:options,id:id},
	 function(data,status){
	 if("success"==data){
		 alert("保存草稿成功！")
		    document.form1.action="<%=basePath %>/check/index";
	        document.form1.method="post";
	        document.form1.submit();

	 }else{
	 alert("保存草稿失败！");
	 }
	 });
	}

 function doUpload() {  
     var formData = new FormData($( "#uploadForm" )[0]);  
     $.ajax({  
          url: '<%=basePath %>/upLoadFile.do' ,  
          type: 'POST',  
          data: formData,  
          async: false,  
          cache: false,  
          contentType: false,  
          processData: false, 
          success: function (data) {
              var a=data;
              var percentageDiv = document.getElementById("percentage");
              percentageDiv.innerHTML ="100%";
        	  document.getElementById("progressBar").value=100;
              document.getElementById("sp_AjaxFile").style.display="none";//设置标签影藏！
              document.getElementById("sp_AjaxFile").value=a;
          },  
          error: function (returndata) {  
              alert(returndata);  
          }  
     });  
}  
 function UpladFile() {
     var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
     var FileController = "<%=basePath %>/uploades";          // 接收上传文件的后台地址 

     // FormData 对象
     var form = new FormData($( "#uploadForm" )[0]);

     // XMLHttpRequest 对象
     var xhr = new XMLHttpRequest();
     xhr.open("post", FileController, true);
     xhr.onload = function () {
       // alert("上传完成!");
     };

     xhr.upload.addEventListener("progress", progressFunction, false);
     xhr.send(form);
   }

   function progressFunction(evt) {
     var progressBar = document.getElementById("progressBar");
     var percentageDiv = document.getElementById("percentage");
     if (evt.lengthComputable) {
       progressBar.max = evt.total;
       progressBar.value = evt.loaded;
       percentageDiv.innerHTML = Math.round(evt.loaded / evt.total * 100) + "%";
       if(evt.loaded==evt.total){
         alert("上传完成100%");
       }
     }
   } 

 </script>
	
            
</script>
 <!-- <script type="text/javascript">

 function upload(){    
     
     $.ajaxFileUpload({  
            type: "POST",  //提交方式   
            url:'project/upload',    
            secureuri:false,    
            fileElementId:'busiAttachment',  
            dataType: 'text/html',  
            success:function(data,status){  
                  
                console.log(data);  
                var json=eval(data);        
                var messageDiv=document.getElementById("project_document");
                document.getElementById("sp_AjaxFile").style.display="none";//设置标签影藏！
                $("#sp_AjaxFile").html(data.resultFile);
                messageDiv.innerHTML="<input type='text' value='success'/>";  
            },  
            error : function(data, status, e) {    
              alert("系统报错，稍后重试！");    
            }  
        });    
}  

    </script> -->
</html>
<script type="text/javascript">
CKEDITOR.replace('content', {
	"filebrowserUploadUrl" : "<%=request.getContextPath()%>/upload"
	});
</script>